home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
tex
/
sed15x.zip
/
SED.LST
< prev
Wrap
File List
|
1991-09-22
|
25KB
|
661 lines
SED(1) USER DOCUMENTATION SED(1)
NAME
sed - the stream editor
SYNOPSIS
sed [-n] [-g] [-e script] [-f sfilename] [filename ]
DESCRIPTION
sed reads each filename line by line, edits each line according to a script
of commands as specified by the -e and -f arguments and then copies the
edited line to the standard output.
OPTIONS
The -e option supplies a single edit command from the next argument; if
there are several of these they are executed in the order in which they
appear. If there is just one -e option and no -f's, the -e flag may be
omitted. An -f option causes commands to be taken from the file sfilename;
if there are several of these they are executed in the order in which
they appear; -e and -f commands may be mixed. The script or sfilename can
be adjacent to the -e or -f or can be the next argument on the command
line. The -g option causes sed to act as though every substitute command
in the following script has a g suffix. The -n option suppresses the
default output.
SCRIPTS
A script consists of one or more sed commands of the following form:
[address[,address]] function [arguments]
Normally sed cyclically copies a line of input into a current text buffer,
then applies in sequence all commands whose addresses select that line and
then copies the buffer to standard output and clears the buffer. The -n
option suppresses normal output so that only commands which do output (e.g.
p) cause any writing to occur. Also, some commands (n, N) do their own
line reads, and some others (o, d, D) cause all commands following in the
script to be skipped (the D command also suppresses the clearing of the
current text buffer that would normally occur before the next cycle).
There is also a second buffer (called the 'hold space' that can be copied
or appended to or from or swapped with the current text buffer.
ADDRESSES
An address is: a decimal number (which matches that numbered line where
line numbers start at 1 and run cumulatively across files), or a '$' (which
matches the last line of input), or a '/regular expression/' (which matches
any line satisfying the expression. The following rules govern the address
matching:
* A command line with no addresses selects every input line.
* A command line with one address selects every input line that matches
that address.
* A command line with two addresses selects the inclusive range from the
first input line that matches the first address up to and including
the next input that matches the second. (If the second address is a
number less than or equal to the line number first selected, only one
line is selected.) Once the second address is matched sed starts
h**2 Documentation 21 September 1991 1
SED(1) USER DOCUMENTATION SED(1)
looking for the first one again; thus, any number of these ranges will
be matched.
* The second address may be in the form of '+number'. This means that
the command will stay selected for number lines after the first
address is satisfied.
* \?regular expression? where ? is any character is identical to
/regular expression/.
* The negation operator '!' preceding a function makes that function
apply to every line not selected by the address(es).
FUNCTIONS
In the following list of functions, the maximum number of addresses
permitted for each function is indicated in parentheses. An argument
denoted 'text' consists of one or more lines, with all but the last ending
with '\' to hide the newline. A command with this type argument must be the
last on any command line or -e argument. Otherwise multiple commands may
appear on a line separated by ';' characters. A command may have a
trailing comment indicated by a '#' character. Comment lines begin with a
'#'. Backslashes in text are treated as described in 'escape sequences
below; they may be used to protect initial whitespace against the
stripping that is done on every line of the script. An argument denoted
'label', 'rfile' or 'wfile' (which specify labels or file names) is not
processed for 'escape sequences'. Therefore a ';' or '#' terminates the
label or file name. This simplifies entering DOS style paths. Each 'wfile'
is created before processing begins. There can be at most 10 distinct
'wfile' arguments.
(1) a text Append the 'text' on output before reading the next input
line.
(2) b [label] Branch to the ':' command with the given 'label'. If no
'label' is given, branch to the end of the script.
(2) c text Change lines by deleting the current text buffer and at the
end of the address range, place 'text' on the output.
Start the next input cycle.
(2) d Delete the current text buffer. Start the next input cycle.
(2) D Delete the first line of the current text buffer (all
characters up to the first newline). Start the next input
cycle.
(2) g Replace the contents of the current text buffer with the
contents of the hold space.
(2) G Append the contents of the hold space to the current text
buffer.
(2) h Copy the current text buffer into the hold space.
h**2 Documentation 21 September 1991 2
SED(1) USER DOCUMENTATION SED(1)
(2) H Append a copy of the current text buffer to the hold space.
(1) i text Insert the 'text' on the standard output.
(2) l [w[file]] List current text buffer on standard output or to a file if
the -w option follows. Non ASCII printable characters are
expanded as shown in the 'escape sequence' section below.
(2) n Copy the current text buffer to standard output. Read the
next line of input into it. The current line number
changes.
(2) N Append the next line of input to the current text buffer,
inserting an embedded newline between the two. The current
line number changes.
(2) p Copy the current text buffer to the standard output.
(2) P Copy the first line of the current text buffer (all
characters up to the first newline) to standard output.
(1) q Quit. Perform any pending outputs (a or r commands) and
terminate sed.
(1) r rfile Read the contents of 'rfile'. Place them on the output
before reading the next input line.
(2) s /regular expression/replacement/flags
Substitute the 'replacement' for instances of the 'regular
expression' in the current text buffer. Any character may
be used instead of '/'. In the 'regular expression' and in
the 'replacement' text \1 - \9 are used to indicate the nth
subexpression indicated by a '\(...\)' expression in the
'regular expression'. In the replacement text an & may be
used to indicate the entire matched expression. If the
replacement text consists only of the a single '%'
character, then a copy of the replacement text for the
previous s command is used as the replacement text for this
co